<?php
// 本类由系统自动生成，仅供测试用途
class UpdateAction extends Action{
    public function index(){
		ini_set('max_execution_time', '1000');
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ';
		$user = M('User');
		$userinfo = $user->select();
		foreach ($userinfo as $u){
			if ($u['tel']!='' && $u['tel']!=NULL){
		
		$cook = array(

			'ASP.NET_SessionId' => 'j330fzrso5o2xrj50lr1v2vl',
			'JASiteCookie' => '',
		);

		$post_data = array(

		);
		//print_r($post_data);
		catcha("http://electsys0.sjtu.edu.cn/edu/index.aspx", 0, $post_data, $cook, 0);


		$post_data['txtUserName']= $u['uid'];
		$post_data['txtPwd']= base64_decode($u['pw']);
		$post_data['rbtnLst']='1';
		$post_data['Button1']='登录';
		//print_r($post_data);
		catcha("http://electsys0.sjtu.edu.cn/edu/index.aspx",0, $post_data, $cook, 0);
		$post_data = array(

		);
		//print_r($post_data);
		catcha("http://electsys0.sjtu.edu.cn/edu/student/sdtinfocheck.aspx",0, $post_data, $cook, 0);
		$post_data = array(

		);
		catcha("http://electsys0.sjtu.edu.cn/edu/StudentScore/B_StudentScoreQuery.aspx",0, $post_data, $cook, 0);
		
		$post_data["ddlXN"] = CCXN;
		$post_data["ddlXQ"]	= CCXQ;
		$post_data["txtKCDM"] = "";
		$post_data["btnSearch"]	= "  查  询  ";

		$result = catcha("http://electsys0.sjtu.edu.cn/edu/StudentScore/B_StudentScoreQuery.aspx",0, $post_data, $cook, 0);
		preg_match_all('|<td align="center">(\S*)\s*</td><td width="180">(\S*)\s*</td><td align="center">(\S*)\s*</td><td align="center">(\S*)\s*</td><td align="center">|', $result, $matches);
		//print_r($matches);
		$score=array();
		for ($i=0;$i<count($matches[1]);$i++)
		{
			$score[$i]['cid']=$matches[1][$i];
			$score[$i]['cname']= str_replace('毛泽东思想和中国特色社会主义理论体系概论','毛概',$matches[2][$i]);
			$score[$i]['credit']=$matches[3][$i];
			$score[$i]['score']=$matches[4][$i];
			
			$score[$i]['uid']=$u['uid'];
			$score[$i]['time']=time();
			$score[$i]['sms'] = 1;
			
			$score[$i]['CCXN']=CCXN;
			$score[$i]['CCXQ']=CCXQ;
			
			$mscore = M('record');
			$scoreinfo = $mscore->where( "uid='{$u['uid']}' AND cid='{$score[$i]['cid']}'" )->find();
			if ($scoreinfo ==NULL){
				//sms
				echo $u['tel'];
				$r = catcha('http://www.tui3.com/api/send/?k=b33fc816fae5dec73ba1696b3c50f321&r=xml&p=1&t='.$u['tel'].'&c=您好,您的'.$score[$i]['cid'].$score[$i]['cname'].'成绩为"'.$score[$i]['score'].'",by@YEPINFO',0);  
				echo $r.'<br>';
				preg_match_all('|(操作成功)|', $r, $matches);
				//print_r($matches);
				if (count($matches[1])>0){
					$u['smsnum']++;
					$user->where( "uid='{$u['uid']}'" )->save($u);
					$mscore->add($score[$i]);
				}
			}
		}
		
			}
		}	
	echo format_time(time())." OK!";
	}
}
?>